package com.geeksaga.dao.ibatis.oracle;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.geeksaga.common.util.DateConvertor;
import com.geeksaga.dao.BbsManagerDao;
import com.geeksaga.dao.ibatis.BaseIBatisDao;
import com.geeksaga.domain.BbsManager;
import com.geeksaga.domain.BbsType;

/**
 * @author newbie
 * @since 0.1
 */
@Repository
public class BbsManagerDaoImpl extends BaseIBatisDao implements BbsManagerDao {

    /* (non-Javadoc)
     * @see com.geeksaga.dao.BbsManagerDao#add(com.geeksaga.dao.BbsManagerDao)
     */
    public BbsManager add(BbsManager manager) throws DataAccessException {
        manager.setRegistTimestamp(DateConvertor.getDateTimeFormat());
        
        return (BbsManager) getSqlMapClientTemplate().insert("BBS_MANAGER.add", manager);
    }

    /* (non-Javadoc)
     * @see com.geeksaga.dao.BbsManagerDao#findByBbsType(com.geeksaga.domain.BbsType)
     */
    @SuppressWarnings("unchecked")
    public Map<String, String> findByBbsType(BbsType type) throws DataAccessException {
        Map<String, String> map = new HashMap<String, String>();
        
        List<BbsManager> list = (List<BbsManager>) getSqlMapClientTemplate().queryForList("BBS_MANAGER.findByBbsType", type);
        Iterator<BbsManager> iterator = list.iterator();
        
        while(iterator.hasNext()) {
            BbsManager manager = iterator.next();
            
            map.put(manager.getUserSid(), manager.getBbsId());
        }
        
        return map;
    }
}